package com.zyl.edthresholdtraining.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyl.edthresholdtraining.entity.UserTestAnswer;
import com.zyl.edthresholdtraining.mapper.UserTestAnswerMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author zhangyulu
 * @description
 * @date 2020/7/31/031
 */
@Slf4j
@Service
public class UserTestAnswerService extends ServiceImpl<UserTestAnswerMapper, UserTestAnswer> {

    public UserTestAnswer getNumberResult(String imageUnitName, String userId) {
        try {
            QueryWrapper<UserTestAnswer> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("image_unit_name",imageUnitName)
                    .eq("user_id",userId);
            List<UserTestAnswer> userTestAnswers = baseMapper.selectList(queryWrapper);
            if (CollectionUtils.isEmpty(userTestAnswers)) {
                return null;
            } else {
                return  userTestAnswers.get(0);
            }
        } catch (Exception e) {
            log.error("sql错误！");
        }
        return null;
    }
}
